package com.safeneeds.linguimana.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionListener;

import org.apache.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;












import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.safeneeds.linguimana.dto.PortConstant;
import com.safeneeds.linguimana.dto.SessionListener;
import com.safeneeds.linguimana.entity.PortGlutLog;
import com.safeneeds.linguimana.entity.PortGlutNotice;
import com.safeneeds.linguimana.entity.PortGlutOnduty;
import com.safeneeds.linguimana.entity.PortGlutStar;
import com.safeneeds.linguimana.entity.PortNews;
import com.safeneeds.linguimana.entity.PortNewsCate;
import com.safeneeds.linguimana.entity.PortVisitData;
import com.safeneeds.linguimana.entity.dao.IPortGlutLogDao;
import com.safeneeds.linguimana.entity.dao.impl.PortGlutLogDao;
import com.safeneeds.linguimana.ser.IBgDutyService;
import com.safeneeds.linguimana.ser.IBgLogService;
import com.safeneeds.linguimana.ser.IBgNewsCateService;
import com.safeneeds.linguimana.ser.IBgNewsService;
import com.safeneeds.linguimana.ser.IBgNoticeService;
import com.safeneeds.linguimana.ser.IBgStarService;
import com.safeneeds.util.base.BaseAction;
import com.safeneeds.util.base.RetType;

/**
 * 门户网站
 * @author gaof
 * @date 2017年2月7日
 */
@Controller
@RequestMapping("portal")
public class webPortAction extends BaseAction{

	/**
	 * 首页展示
	 * @return
	 */
	@Resource(name="bgNewsCateService")
	private IBgNewsCateService bgNewsCateService;
	@Resource(name="bgNewsService")
	private IBgNewsService bgNewsService;
	@Resource(name="bgNoticeService")
	private IBgNoticeService bgNoticeService;
	@Resource(name="bgDutyService")
	private IBgDutyService bgDutyService;
	@Resource(name="bgStarService")
	private IBgStarService bgStarService;
	@Resource(name="bgLogService")
	private IBgLogService bgLogService;
	@RequestMapping("index1.dop")
	public String index(ModelMap modelMap ,HttpSession session,HttpServletRequest req) throws Exception{
		//获取置顶根分类信息
		List<PortNewsCate> cate=bgNewsCateService.listNewsCate_1(9);
		//获取所有有图片的新闻
		List<PortNews> newsimage=bgNewsService.getNewExistImage();
		//获取置顶新闻
		PortNews top=bgNewsService.getTopNews();
		//获取最新新闻
		List<PortNews> newnews=bgNewsService.getNewNews();
		//获取最新通告
		List<PortGlutNotice> Announcement=bgNoticeService.getNotice();
		//获取今日值班信息
		List<PortGlutOnduty> duty=bgDutyService.getDuty();
		//获取警星信息
		List<PortGlutStar> star=bgStarService.getStar();
		//获取专题栏目
		List<PortNewsCate> specialcate=bgNewsCateService.getSpecialCate(5,"专题栏目");
		//获取置中的栏目信息
	    List<List<PortNewsCate>> midchildcate=bgNewsCateService.getChildCate(4,3); 
	    //获取统计信息
	    PortVisitData portVisitData=bgLogService.getVisitData();
	   /* 
	    * 讲前台用户请求记录到数据库
	    * */
	    bgLogService.add(req);
	    int current= SessionListener.count;
    	modelMap.put("midchildcate", midchildcate);
		modelMap.put("cate", cate);
		modelMap.put("newsimage", newsimage);
		modelMap.put("top", top);
		modelMap.put("newnews", newnews);
		modelMap.put("Announcement", Announcement);
		modelMap.put("duty", duty);
		modelMap.put("star", star);
		modelMap.put("specialcate", specialcate);
		modelMap.put("midchildcate", midchildcate);
		modelMap.put("current", current);
		modelMap.put("portVisitData", portVisitData);
		
		
		return getViewsModelPathPortals("index");
	}

	@ResponseBody
	@RequestMapping("index_news.dop")
	public RetType ChildCateNews(ModelMap map,@RequestParam(value="cateId")String cateId){
		//获取分类新闻
		RetType catenews=bgNewsService.getCateNews1(cateId,9);		
		return catenews;		

	}
	@RequestMapping("index_search.dop")
	public String index_1(HttpServletRequest request,ModelMap map){
		/*String key=request.getParameter("key");
		List<PortNews> searchNews=bgNewsService.getSearchNews(key);
		map.put("searchNews",searchNews);*/
		
		return "/views/police/search";
		

	}
	@RequestMapping("index.dop")
	public String index2(){	
		return "/views/police_lg/index";
		
	}
	
}
